/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author lyoe
 */
class TopicSpeakerShip {
    User user
    Topic topic

    static TopicSpeakerShip link(user, topic) {
        def ts = TopicSpeakerShip.findByUserAndTopic(user, topic)
        if(!ts) {
            ts = new TopicSpeakerShip()
            user?.addToTopicSpeakerShips(ts)
            topic?.addToTopicSpeakerShips(ts)
            ts.save()
        }
        return ts
    }

    static void unlink(user, topic) {
        def ts = TopicSpeakerShip.findByUserAndTopic(user, topic)
        if(ts) {
            user?.removeFromTopicSpeakerShips(ts)
            topic?.removeFromTopicSpeakerShips(ts)
            ts.delete()
        }
    }
}

